<template>
	<view>
		<view v-if="buyList.length>0">
			<myBuy :list="buyList"></myBuy>
		</view>

		<view class="no-data" v-else>
			<image src="../../static/img/noData.png" mode=""></image>
			<view>暂无数据，<navigator open-type="switchTab" url="/pages/buy/index">快去求购吧</navigator>
			</view>
		</view>
		<view class="loading flex flai fljc" v-if="loading">
			<image src="../../static/img/loading2.gif" mode="" v-if="loadPic"></image>
			<text>{{msg}}</text>
		</view>
		<view style="height: 60rpx;"></view>
	</view>
</template>

<script>
	import myBuy from '../components/myBuy/index.vue'
	import API from '../../api/index.js'
	export default {
		components: {
			myBuy
		},
		data() {
			return {
				page: 1,
				buyList: [],
				isPull: true,
				loading: false,
				msg: '加载中...',
				loadPic: true
			}
		},
		onLoad() {
			this.buyList = []
			this.getList()
		},
		methods: {
			getList() {
				var data = {
					page: this.page,
					size: 10,
					type: 1
				}
				this.loading = true
				this.msg = '加载中...'
				this.loadPic = true
				API.indexHome.myBuySigle(data).then(res => {
					if (res.errno == '0') {
						var needs = res.data

						if (needs.length < 10 && needs.length > 0) {
							this.isPull = false
							this.msg = '主人我是有底线的哟~~'
							this.loadPic = false
						} else {
							this.isPull = true
							setTimeout(() => {
								this.loading = false
							}, 1000)
						}
						this.buyList = [...this.buyList, ...needs]
					}
				})
			},
			onPullDownRefresh() {
				this.page = 1
				this.buyList = []
				this.getList()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},
			onReachBottom() {
				if (this.isPull) {
					var page = this.page + 1
					console.log(page)
					this.page = page
					this.getList()
				}
			}
		}
	}
</script>

<style>
	.no-data {
		text-align: center;
		margin-top: 256rpx;
	}

	.no-data image {
		width: 341rpx;
		height: 196rpx;
		margin: 0 auto;
		display: block;
	}

	.no-data view {
		font-size: 28rpx;
		color: #999999;
		display: block;
		margin-top: 20rpx;
	}

	.no-data view navigator {
		font-size: 28rpx;
		color: #999999;
		display: inline-block;
	}
</style>
